package com.b.controller;

import com.b.domain.Video;
import com.b.service.VideoService;
import com.b.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.elasticsearch.core.SearchPage;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 视频表(video)表控制层
 *
 * @author xxxxx
 */
@RestController
@RequestMapping("/video")
public class VideoController {
    /**
     * 服务对象
     */
    @Resource
    private VideoService videoService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Video selectOne(Integer id) {
        return videoService.selectByPrimaryKey(id);
    }

    @GetMapping("list")
    public List<Video> list() {
        return videoService.list();
    }
    @GetMapping("list2")
    public List<Video> list2() {
        return videoService.list2();
    }


    //审核视频(通过没有原因,拒绝有)
    @RequestMapping("audit")
    public Result audit(@RequestParam( "id" ) Integer id, @RequestParam("result" )String result, @RequestParam("reason") String reason) {
        return videoService.audit(id, result, reason);
    }
    //删除视频
    @RequestMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        return videoService.delete(id);
    }
    @GetMapping("getByCategoryId")
    public SearchPage<Video> getByCategoryId(@RequestParam("CategoryId") Integer CategoryId,
                                        @RequestParam(value = "pageNum", defaultValue = "1") Integer page,
                                        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
                                        ) {
        PageRequest pageRequest = PageRequest.of(page - 1, pageSize);
        return videoService.getByCategoryId(CategoryId, pageRequest);
    }
    @PostMapping("update")
    public Result update(@RequestParam("videoId") Integer videoId, @RequestParam(value = "categoryId") Integer categoryId) {
        // 正常增/改标签逻辑
        return videoService.update(videoId, categoryId);
    }



}
